const cloud = require('wx-server-sdk');
cloud.init();

exports.main = async (event, context) => {
  const { filePath, cloudPath } = event;
  try {
    // 上传文件到云存储
    const uploadRes = await cloud.uploadFile({
      cloudPath,
      filePath
    });

    // 返回文件 ID
    return {
      code: 0,
      data: {
        fileID: uploadRes.fileID
      }
    };
  } catch (err) {
    console.error('上传失败：', err);
    return {
      code: -1,
      message: '上传失败'
    };
  }
};